# -*- coding: utf8 -*-

from threading import RLock

class Project( object ):

    _lock = None
    _table = None
    _db_name = "duplicates"

    tables = (
        "option", "directory", "file", "hash", "image",
        "image_vector10", "image_vector100",
        "image2image", "file2file",
    )

    def __init__( self ):
        self._lock = RLock()
        self._table = {}


    def getTable(self, name):
        self._lock.acquire()
        if name not in self._table:
            if name == "option":
                from project.sqlite3_db.table_option import TableOption
                self._table[ name ] = TableOption(self._db_name)
            elif name == "directory":
                from project.sqlite3_db.table_directory import TableDirectory
                self._table[ name ] = TableDirectory(self._db_name)
            elif name == "file":
                from project.sqlite3_db.table_file import TableFile
                self._table[ name ] = TableFile(self._db_name)
            elif name == "hash":
                from project.sqlite3_db.table_hash import TableHash
                self._table[ name ] = TableHash(self._db_name)
            elif name == "image":
                from project.sqlite3_db.table_image import TableImage
                self._table[ name ] = TableImage(self._db_name)
            elif name == "image_vector10":
                from project.sqlite3_db.table_image_vector10 import TableImageVector10
                self._table[ name ] = TableImageVector10(self._db_name)
            elif name == "image_vector100":
                from project.sqlite3_db.table_image_vector100 import TableImageVector100
                self._table[ name ] = TableImageVector100(self._db_name)
            elif name == "image2image":
                from project.sqlite3_db.table_image2image import TableImage2Image
                self._table[ name ] = TableImage2Image(self._db_name)
            elif name == "file2file":
                from project.sqlite3_db.table_file2file import TableFile2file
                self._table[ name ] = TableFile2file(self._db_name)
        self._lock.release()
        return self._table[ name ]

    pass
